home *** CD-ROM | disk | FTP | other *** search
/ Gigarom 1 / Gigarom Macintosh Archives (Quantum Leap)(CDRM1080320)(1993).iso / FILES / HYP / T-Z / Windoids.cpt / Windoid 1.6.1 / card_13037.txt < prev    next >
Text File  |  1989-04-13  |  6KB  |  141 lines

  1. -- card: 13037 from stack: in.1
  2. -- bmap block id: 13182
  3. -- flags: 0000
  4. -- background id: 10029
  5. -- name: 
  6. ----- HyperTalk script -----
  7.  
  8.  
  9.  
  10.  
  11. -- part contents for background part 11
  12. ----- text -----
  13. The following is a small collection of utility scripts that I find useful in my work.
  14.  
  15. ‚Ä¢ Finding the Finder
  16.  
  17. When running under MultiFinder, the following script will hide the HyperCard window, the Message window, and any tearoff windoids and put you in the Finder.  It is handy when installed into a button on the Home card, especially when you are working on a small-screen Mac.  When you choose HyperCard from the Apple menu, the HyperCard windows will reappear exactly as you left them.  Note:  Hide/Show card window is a new feature of version 1.1, so you must be running that version for this script to work.
  18.  
  19. on mouseUp
  20.   hide card window
  21.   doMenu "finder"
  22. end mouseUp
  23.  
  24. The following is another handy script that uses hide/show card window.  This utility allows you to toggle between settings for small and large screen Macs.  One useful example is to put the word "setWindow" under 
  25. "StartUp" in your Home Stack script and put the following script at the end.  When you first open HyperCard you can have your windows right where you want them.
  26.  
  27. on setWindow
  28.   answer "Which CPU?" with "Mac II" or "Mac +"
  29.   if it is "Mac II" then
  30.     show menuBar
  31.     show card window at 20,50
  32.     show tool window at 524,198
  33.     show message window at 0,370
  34.   else if it is "Mac +" then
  35.     show card window at 0,0
  36.     hide tool window
  37.     hide pattern window
  38.     show msg at 30,260
  39.     hide msg
  40.   end if
  41. end setWindow
  42.  
  43.  
  44. ‚Ä¢ Recovering lost buttons
  45.  
  46. Well, this script won't recover anything you've already lost, but it may save you a headache in the future.  Put this script in the Home stack script. When ever you try to get rid of a button this script will complain and give you the chance to get your button back.
  47.  
  48. on deleteButton
  49.   answer "Do you REALLY want to delete that button?" ¬¨
  50.     with "No, Copy it" or "Yes"
  51.   if it is "No,Copy it" then
  52.     doMenu "copy button"
  53.     doMenu "paste Button"
  54.   end if
  55. end DeleteButton
  56.  
  57. ‚Ä¢ Changing a button's font style
  58.  
  59. Yes, there are alternatives to those generic round rect buttons with text in good ol' Chicago.  Buttons can be assigned a font and font style through a script.  If you wish to change the font of a single button, just type set the textFont of card button "fred" to "Geneva" into the message box, and hit return.  In addition, you can set the size (set textSize...), style (set textStyle...) alignment (set TextAlign...), and height (set textHeight...),  of any button.  My current personal favorite is a shadowed button with 10 point Geneva text.
  60.  
  61. Once you get the hang of changing the text-related attributes of buttons, it can get a bit tedious to set all these styles by typing lines into the msg box.  The following script installed into a functionKey and invoked from the message box can be a real finger saver.  It will change the button you specify to your choice of font, font size, and font style.
  62.  
  63. on ChangeButton
  64.    ask "Which button?" with "Card button ID " & id of last button
  65.    if it is empty then exit ChangeButton
  66.    put it into btnname
  67.  
  68.    ask "Font, Size, Style?" with "Geneva,9,bold"
  69.    if it is empty then exit ChangeButton
  70.  
  71.    if first item of it is not empty
  72.    then do "set textFont of " & btnname & " to " & first item of it
  73.  
  74.    if item 2 of it is not empty
  75.    then do "set textSize of " & btnname & "to " & item 2 of it
  76.  
  77.    if item 3 of it is not empty
  78.    then do "set textStyle of " & btnname & "to " & item 3 of it
  79.  
  80. end changeButton
  81.  
  82. Invoking this script will present two dialogs.  In the first dialog, enter the full name of any button on that card.  Remember to specify card or background button, and refer to it by name, id or number. (bkgnd btn 
  83. "New button".)  In the second dialog, enter the font, size and style, separated by commas.  If you do not wish to change one of the attributes, leave it blank (font, ,style) or enter what it currently is set to.
  84.  
  85. An alternative solution:
  86. Locked fields can behave just like buttons.  Create a field, enter your title into it, choose your text style through the Textstyle window, then lock the field.  You can now put any "mouse" handler (on mouseUp,etc) into the script of this field and it will behave just like a rect button, with the exception of hiliting.
  87.  
  88. ‚Ä¢ Which line did I click on?
  89.  
  90. The following function scripts return which line of a field was clicked on. In this case, "line" is defined as the number of textHeight increments from the top of the field, and not as a line of text ending with a carriage return.  Also, the field needs to be locked when you click on it, or you will end up putting an insertion point in the field, not executing a script.
  91.  
  92. A simple example of how this might be useful:
  93. Put the following handler as well as one of the functions into the script of a field.  The field should be locked and contain some lines of text that do not wrap.
  94.  
  95. on mouseUp
  96.   answer "You clicked on line " & quote & line lineclicked() ¬¨
  97.   of card field "newt" & quote
  98. end mouseUp
  99.  
  100. function lineClicked
  101.   return ((the mouseV - item 2 of the rect of the target) ¬¨
  102.   div the textHeight of the target) + 1
  103. end lineClicked
  104.  
  105. If you wish this to work on a scrolling field, it becomes a bit more complex to account for the possiblity of lines scrolled off the top.
  106.  
  107. function lineClicked
  108.   return (round((the scroll of the target / the textHeight ¬¨
  109.   of the target) ¬¨
  110.   +  (((the mouseV - item 2 of the rect of the target) ¬¨
  111.   div the textHeight of the target) + 1)))
  112. end lineClicked
  113.  
  114.  
  115. ‚Ä¢ AutoCompaction will keep your stacks trim
  116.  
  117. Install this script into your Home stack script. If any stack you are about to leave needs to be compacted, it will let you know.  This is an easy way to ensure you always have lots of room on your hard disk (...for more stacks.)
  118.  
  119. on closeStack
  120.   if the freeSize of this stack >= 15000 then
  121.     answer "This stack has " & round (the freeSize of this ¬¨
  122.     stack/1024) & "k free, Compact?" with  "NO" or "OK"
  123.     if it is "OK" then doMenu "compact stack"
  124.   end if
  125. end closeStack
  126. Ô£ø
  127.  
  128. -- part contents for background part 17
  129. ----- text -----
  130. HyperCard
  131. Utility
  132. Scripts
  133.  
  134. -- part contents for background part 18
  135. ----- text -----
  136. ‚Ä¢ by
  137. Robin Shank
  138.  
  139. -- part contents for background part 19
  140. ----- text -----
  141. volume 1 ‚Ä¢  number  6  ‚Ä¢  card 8  ‚Ä¢